﻿import QtQuick 2.15
import QtQuick.Controls 2.15

/*
  顶部展示
*/

Item {
    id:backGround
    width: screenWidth
    height: 150


    Rectangle{
        anchors.fill: backGround
        color: "#00bfff"
        border.width: 5
        border.color: "#FFFAFA"
    }

    // 报警滚动屏幕信息
    property string m_showText

    property int m_contentWidth


    function warningSignalChanged(msgSignal)
    {
        // console.log("msgSignal:" + msgSignal);

        if(msgSignal === m_showText)
        {
            return;
        }

        if("现在报警信号:" === msgSignal)
        {
            m_showText = msgSignal;
            warningBack.visible = false
            warnningTest.visible = false;
            sequentialAnimation.stop();
        }
        else
        {
            m_showText = msgSignal;
            warningBack.visible = true
            warnningTest.visible = true;
            m_contentWidth = warnningTest.contentWidth
            sequentialAnimation.restart();
        }
    }


    Component.onCompleted: {
        dateShow_Text.text = Qt.formatDateTime(new Date(), "yyyy/MM/dd")
        timeShow_Text.text = Qt.formatDateTime(new Date(), "hh:mm:ss")

        // 连接报警信号与槽
        Cpp_Connect.sig_WarningSignalChanged.connect(warningSignalChanged);
        sequentialAnimation.start();

    }

    Rectangle{      // 报警部分
        id:warningBack
        anchors.left: backGround.left
        anchors.leftMargin: 5
        anchors.top: backGround.top
        anchors.topMargin: 5
        width: 820
        height: 140
        clip:true
        color: "gold"
        // color: "red"

        Text{
            id:warnningTest
            width : parent.width
            height : parent.height
            y:10
            // anchors.verticalCenter: parent.verticalCenter
            horizontalAlignment: Text.AlignLeft
            font.pixelSize: 120
            font.bold: true
            color: "red"
            text:m_showText
        }

        SequentialAnimation {
            id: sequentialAnimation
            loops: Animation.Infinite // 无限循环
            running: true

            // 从当前位置移动到 -width 的位置
            NumberAnimation {
                target: warnningTest
                properties: "x"
                from: warnningTest.width;
                to: -warnningTest.contentWidth
                duration: 5000 // 持续时间5000毫秒
                easing.type: Easing.Linear // 线性插值
            }

            // 瞬间跳回原点
            NumberAnimation {
                target: warnningTest
                properties: "x"
                to: 0
                duration: 0 // 瞬间完成
            }
        }

    }

    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 5
        anchors.top: backGround.top
        anchors.topMargin: 5
        width: 600
        height: 140
        color: "transparent"
        z:10
        // color: "red"

        Text{
            // anchors.centerIn: parent
            anchors.verticalCenter: parent.verticalCenter
            horizontalAlignment: Text.AlignLeft
            font.pixelSize: 80
            font.bold: true
            text: Cpp_Connect.ExtraLong_Locating ? qsTr("超长定位中") :
                  Cpp_Connect.Long_WorkState ? qsTr("超长加工中") :
                  Cpp_Connect.Short_WorkState ? qsTr("超短加工中") :
                  Cpp_Connect.JM_WorkState ? qsTr("角码加工中") :
                  Cpp_Connect.MechineRunningState ? qsTr("电机运行中") :
                  Cpp_Connect.FindZeroState ? qsTr("设备找零中") :
                  Cpp_Connect.ZeroGoingState ? qsTr("设备回零中") :
                                               qsTr("")

            color : Cpp_Connect.ExtraLong_Locating ? "gold" :
                    Cpp_Connect.Long_WorkState ? "gold" :
                    Cpp_Connect.Short_WorkState ? "gold" :
                    Cpp_Connect.JM_WorkState ? "gold" :
                    Cpp_Connect.MechineRunningState ? "red" :
                    Cpp_Connect.FindZeroState ? "red" :
                    Cpp_Connect.ZeroGoingState ? "gold" :
                                                 qsTr("")

        }

    }






    Timer{
        repeat: true
        running: true
        onTriggered: {
            dateShow_Text.text = Qt.formatDateTime(new Date(), "yyyy/MM/dd")
            timeShow_Text.text = Qt.formatDateTime(new Date(), "hh:mm:ss")
        }
    }

    Text{
        id:dateShow_Text
        anchors.top: backGround.top
        anchors.topMargin: 10
        anchors.right: backGround.right
        anchors.rightMargin: 10
        font.pixelSize: 40
        color: "white"
    }

    Text{
        id:timeShow_Text
        anchors.top: backGround.top
        anchors.topMargin: 60
        anchors.right: backGround.right
        anchors.rightMargin: 10
        font.pixelSize: 40
        color: "white"
    }


    Rectangle{
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 5
        anchors.right: backGround.right
        anchors.rightMargin: 5
        width: 200
        height: 50
        color: "transparent"

        Text{       // 界面标题
            anchors.centerIn: parent
            // anchors.verticalCenter: parent.verticalCenter
            horizontalAlignment: Text.AlignRight
            // verticalAlignment: Text.AlignRight
            font.pixelSize: 30
            font.bold: true
            text:   processWindow.visible ? qsTr("手动加工界面") :
                    lg_ChooseWindow.visible ? qsTr("料高选择界面") :
                    ls_LocationWindow.visible ? qsTr("拉手定位界面") :
                    extraLongProcessWindow.visible ? qsTr("超长加工界面") :
                    extraShortProcessWindow.visible ? qsTr("超短加工界面") :
                    pl_ProcessWindow.visible ? qsTr("排料加工界面") :
                    jm_ProcessWindow.visible ? qsTr("角码加工界面") :
                    io_MonitorWindow.visible ?  qsTr("IO监控界面") :
                    printerSettingWindow.visible ? qsTr("打印机设置界面") :
                    netWorkFormulaWindow.visible ? qsTr("网络料单界面") :
                    qrCodeFormulaWindow.visible ? qsTr("二维码料单") :
                    advanceSettingWindow.visible ? qsTr("高级设置界面") :
                    servoParameterSetting.visible ? qsTr("伺服参数设置") :
                    materialRackParameter.visible ? qsTr("托料参数设置") :
                    locationCompensateSetting.visible ? qsTr("位置补偿设置") :
                    anyLocationCompensate.visible ? qsTr("任意位置补偿") :
                    changePasswdWindow.visible ? qsTr("修改密码") :
                    deviceLayoutWindow.visible ? qsTr("设备配置界面") :
                                                    qsTr("管理界面")
        }
    }

}
